package com.geek.javase.ch02.test6;

/*
 *@author wangpeng
 *2025/10/10 20:06
 *@description TODO
 */
public class Users {
    //属性
    private String name;
    private String address;
    private String phone;

    //一对多关联
    private Orders[] orders;
    //无参构造
    public Users(){
    }
    //有参构造
    public Users(String name, String address, String phone) {
        this.name = name;
        this.address = address;
        this.phone = phone;
    }
    public Users(String name, String address, String phone, Orders[] orders) {
        this.name = name;
        this.address = address;
        this.phone = phone;
    }
    //getter方法
    public String getName() {
        return name;
    }

    public String getAddress() {
        return address;
    }

    public String getPhone() {
        return phone;
    }

    public Orders[] getOrders() {
        return orders;
    }
    //setter方法
    public void setName(String name) {
        this.name = name;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void setOrders(Orders[] orders) {
        this.orders = orders;
    }
    //下单方法
    public void xiaDan(){
        System.out.println("用户姓名："+name);
        System.out.println("用户地址："+address);
        System.out.println("用户手机号："+phone);

        System.out.println("============订单信息===========");
        if(orders!=null){
            //foreach迭代  for(元素类型 临时变量名 : 数组名){}
            for (Orders order : orders) {
                if(order!=null){
                    System.out.println("订单编号："+order.getNo());
                }
            }
        }
    }
}

